import {base,promptBox,toast} from 'nc-lightapp-front';
import requestApi from '../requestApi';
import {updataFormData, updatacardTableData} from 'ssccommon/utils/changePageData';
import {getExcelImportConfig} from "../ExcelImportUtil";
import { beforeUpdatePage, updatePage } from 'ssccommon/utils/updatePage';
import { excludeBodyKey,zzhllxLogic } from "../ExpenseUtils"
import _ from 'lodash-es'

export default function afterEvent(props,moduleId,key,value,changedrows,index,attr) {
    let multiLang = props.MutiInit.getIntl(2011);
    let paramdata = {};
    let moduleid =moduleId =="head"?"headform":moduleId;
    let pagecode = window.presetVar.pagecode;
    let bodys = window.presetVar.lsBodys;
    let bodyarr = [];
    let hideTable = this.state.hideTables;
    let _this = this;
    bodys.map((one)=>{
        if(hideTable.indexOf(one)<0){
            bodyarr[bodyarr.length] = one;
        }
    })

    paramdata = {
        "value":value,
        "tableid":moduleid,
        "field":key,
        "uistate":window.presetVar.pagestatus,
        "tradetype":window.presetVar.tradetype,
        "oldvalue":'',
        "pagecode":pagecode,
        "appcode": window.presetVar.appcode
    }
    if(moduleid!="headform"){
        paramdata.changeRowId=changedrows[0].rowid;
    }else{
        paramdata.value = value.value;
    }

    switch(moduleId) {
        case 'head' :
            switch(key) {
                case 'pk_org'://表头财务组织
                case 'pk_org_v'://表头财务组织
                case 'pk_pcorg': // 利润中心
                case 'djrq'://表头单据日期
                case 'bzbm'://表头币种
                case 'bbhl'://表头本币汇率
                case 'dwbm_v'://表头借款报销人单位版本
                case 'dwbm'://表头借款报销人单位
                case 'fydwbm_v'://表头费用承担单位版本
                case 'fydwbm'://表头费用承担单位
                case 'pk_payorg_v'://表头支付单位版本
                case 'pk_payorg'://表头支付单位
                case 'deptid_v':// 表头报销人部门版本
                case 'deptid':// 表头报销人部门
                case 'fydeptid_v':// 表头费用承担部门版本
                case 'fydeptid':// 表头费用承担部门
                case "jkbxr"://借款报销人
                case "receiver"://表头收款人
                case "szxmid"://表头收支项目
                case "skyhzh"://表头个人银行账户
                case "jobid"://表头项目
                case "freecust"://散户
                case "custaccount"://表头客商银行账户
                case "paytarget"://表头收款对象
                case "assume_amount"://分摊页签表体承担金额编辑后事件
                case "assume_org"://分摊页签表体承担单位编辑后事件
                case "hbbm"://表头供应商
                case "customer"://表头客户
                case "customer_v":
                case "hbbm_v":
                case "zzhllyrq"://组织汇率来源日期
                case "zzhllx"://组织汇率类型
                case "zzhllx.rate_category":

                    // props.form.setFormItemsDisabled('head',{'zzhllx':false});
                    // props.form.setFormItemsDisabled('head',{'bbhl':false});
                    // props.form.setFormItemsDisabled('head',{'zzhllyrq':false});
                    if (key === 'pk_org_v') {
                        if(value==undefined||value.value==null){
                            break;
                        }
                    }
                    if (key == 'paytarget' && props.form.getFormItemsVisible('head', 'paytarget')) {
                        if (value.value == '0') {
                            props.form.setFormItemsDisabled('head', {
                                hbbm: true,
                                hbbm_v: true,
                                customer: true,
                                customer_v: true,
                                custaccount: true,
                                receiver: false,
                                freecust: true,
                                skyhzh: false
                            });
                        } else if (value.value == '1') {
                            props.form.setFormItemsDisabled('head', {
                                receiver: true,
                                customer: true,
                                customer_v: true,
                                hbbm: false,
                                hbbm_v: false,
                                custaccount: false,
                                freecust: false,
                                skyhzh: true
                            });
                        } else if (value.value == '2') {
                            props.form.setFormItemsDisabled('head', {
                                hbbm: true,
                                hbbm_v: true,
                                receiver: true,
                                customer: false,
                                customer_v: false,
                                custaccount: false,
                                freecust: true,
                                skyhzh: true
                            });
                        }
                    }
                   
                    //表头修改后数据后台需要的结构， 一主一子  一主多子
                    let billdata = props.createHeadAfterEventData('20110ETEA_2641_IWEB', "head", bodyarr, moduleId, key, value);
                    console.log('表头字段change后表头标题数据结构：', billdata)
                     // let send_headdata = {billdata,paramdata};
                    billdata.card.head.userjson = JSON.stringify(paramdata);
                    billdata.templetid =props.meta.getMeta().pageid;
                    // send_headdata.templateid = props.meta.getMeta().pageid;
                    requestApi.valueChange({
                        data: billdata.card,
                        success: (data)=> {
                            //设置表头数据
                            // TOP 性能优化，变更页面数据更新方法 chengwbc MOD
                            // props.form.setAllFormValue({[presetVar.head.head1]: requestApi.filterDatas(data.head[presetVar.head.head1])});
                            updataFormData(props, presetVar.head.head1, requestApi.filterDatas(data.head[presetVar.head.head1]));
                            // BTM 性能优化，变更页面数据更新方法
                            window.presetVar.reloadHead = requestApi.filterDatas(data.head[presetVar.head.head1]);
                            let org_currinfo = props.form.getFormItemsValue(presetVar.head.head1,'bbhl');
                            if(key=='bzbm' &&org_currinfo.value!=undefined && org_currinfo.value!=null && parseFloat(org_currinfo.value) == parseFloat(1) )
                            {
                                props.form.setFormItemsDisabled(presetVar.head.head1,{'bbhl':true});
                            }
                            
                            //设置表体数据
                            bodyarr.forEach((item) =>{
                                // TOP 性能优化，变更页面数据更新方法 chengwbc MOD
                                const filterbodydatas  =  data.bodys[item]
                                updatacardTableData(props, item, filterbodydatas);
                                // BTM 性能优化，变更页面数据更新方法
                            })
                            //表头值变化后为表体元数据赋值
                            let headrows = data.head[presetVar.head.head1].rows[0].values;
                            let metas  = props.meta.getMeta();
                            //重设表体部分字段默认值（收款对象、收款人、个人银行账号、供应商、客户、客商银行账户、散户）
                            metas = resetBodyInitValue(metas, bodyarr, headrows, key);
                            requestApi.setbodyinitvalue(metas,headrows);

                            if (data.userjson && JSON.parse(data.userjson)) {
                                let djlx = JSON.parse(data.userjson);
                                if (djlx && djlx.ISCONTRAST && djlx.jkyjye && djlx.jkyjye > 0) {//是否冲借款
                                    window.presetVar["ISCONTRAST"] = djlx.ISCONTRAST;
                                }else{
                                    window.presetVar["ISCONTRAST"] = "N";
                                }
                            }
                        }
                    })

                    let currentrow_bzbm = props.form.getFormItemsValue(presetVar.head.head1,'bzbm');
                    // 新增汇率适配逻辑
                    let rate_category =  props.form.getFormItemsValue(presetVar.head.head1,'zzhllx.rate_category'); 
                    zzhllxLogic(currentrow_bzbm,rate_category,'head',props)

                    break;
                case "isexpamt"://待摊
                    if(value.value == true){
                        let accrued_verify = props.cardTable.getAllRows("accrued_verify");
                        if(accrued_verify!=null && accrued_verify.length>0)
                        {
                            props.form.setFormItemsValue('head',{'isexpamt':{value:false,display:null}})
                            toast({content:this.multiLangJson['201102BCLF-0051'],/*"报销单已经核销预提，不可进行待摊!",*/color:'warning'}); 
                        }else{
                            props.form.setFormItemsVisible('head',{"start_period":true,"total_period":true});
                            props.form.setFormItemsDisabled('head',{'start_period':false,'total_period':false});
                        }
                  
                    }else{
                        promptBox({
                            color: 'warning',               // 提示类别默认"success"， "success"/"info"/"warning"/"danger",非必输
                            content: this.multiLangJson['201102BCLF-0052'],//'即将取消标志"待摊",是否继续？' ,            // 提示内容,非必输
                            noFooter: false,                // 是否显示底部按钮(确定、取消),默认显示(false),非必输
                            noCancelBtn: false,             // 是否显示取消按钮,，默认显示(false),非必输
                            beSureBtnName: this.multiLangJson['2011-0003'],//"确定",          // 确定按钮名称, 默认为"确定",非必输
                            cancelBtnName: this.multiLangJson['2011-0002'],//"取消",          // 取消按钮名称, 默认为"取消",非必输
                            beSureBtnClick: function(){
                                props.form.setFormItemsDisabled('head',{"start_period":true,"total_period":true});
                                props.form.setFormItemsVisible('head',{"start_period":false,"total_period":false});
                            },
                            cancelBtnClick:function(){
                                props.form.setFormItemsValue('head',{'isexpamt':{value:true,display:null}})
                            }
                        })

                    }
                break;
                case "iscostshare"://分摊
                    if(value.value == true){
                        //校验报销金额为0，不可分摊
                        let amount = props.form.getFormItemsValue("head","total").value;
                        if(parseFloat(amount) ==0){
                            props.form.setFormItemsValue('head',{'iscostshare':{value:false}});
                            toast({color:"danger",content:multiLang && multiLang.get("201102BCLF-0060")});
                        } else {
                            let accrued_verify = props.cardTable.getAllRows("accrued_verify");
                            if(accrued_verify!=null && accrued_verify.length>0)
                            {
                                props.form.setFormItemsValue('head',{'iscostshare':{value:false}});
                                toast({content:this.multiLangJson['201102BCLF-0049'],/*"报销单已经核销预提，不可进行分摊!",*/color:'warning'});
                                
                            }else{
                                props.form.setFormItemsDisabled("head",{'fydwbm_v':true});
                                setImportConfig(this);//设置导入按钮
                                _this.setState({hideTables:[]})
                            }
                        }
                    }else{
                        promptBox({
                            color: 'warning',               // 提示类别默认"success"， "success"/"info"/"warning"/"danger",非必输
                            title: this.multiLangJson['201101BXBJ-0008'],//"提示信息",                // 提示标题, 默认不同类别下分别为："已成功"/"帮助信息"/"请注意"/"出错啦",非必输
                            content: this.multiLangJson['201102BCLF-0014'],//'即将删除费用明细数据，是否继续？' ,            // 提示内容,非必输
                            noFooter: false,                // 是否显示底部按钮(确定、取消),默认显示(false),非必输
                            noCancelBtn: false,             // 是否显示取消按钮,，默认显示(false),非必输
                            beSureBtnName: this.multiLangJson['2011-0003'],//"确定",          // 确定按钮名称, 默认为"确定",非必输
                            cancelBtnName: this.multiLangJson['2011-0002'],//"取消",          // 取消按钮名称, 默认为"取消",非必输
                            beSureBtnClick: function(){
                                props.form.setFormItemsDisabled("head",{'fydwbm_v':false});
                                 //清空分摊页签明细
                                 let csDetailRows = props.cardTable.getAllRows("er_cshare_detail");
                                 if(csDetailRows != null && csDetailRows.length > 0){
                                     let emptyArr = {rows:[]};
                                     props.cardTable.setTableData("er_cshare_detail",emptyArr);
                                 }
                                _this.setState({hideTables:['er_cshare_detail']})
                            },
                            cancelBtnClick:function(){
                                props.form.setFormItemsValue('head',{'iscostshare':{value:true,display:null}});
                            }
                        })

                        
                    }
                break;
                // case "bzbm"://币种
                //     requestApi.valueChange({
                //         data: send_data,
                //         success: (data)=> {
                //             console.log(data);handleLoadDataResDada
                //             props.form.setAllFormValue({[presetVar.head.head1]:data.head[presetVar.head.head1]});
                //             Object.keys(data.bodys).forEach((item) =>{
                //                 props.cardTable.setTableData(iem, data.bodys[item]);
                //             });
                //         }
                //     });
                //     break;
                default:
                    break;
            }
             //bugfix 表头字段编辑后，需要重新设置一下表体的收款对象相关字段的可编辑性
             //编辑后事件控制字段可编辑性需要放到valuechange之后
             let bbhlFlag = props.form.getFormItemsDisabled('head', 'bbhl'); //表头本币汇率编辑性
             let zzhllxFlag = props.form.getFormItemsDisabled('head', 'zzhllx'); //表头本币汇率类型编辑性
             let zzhllyrqFlag = props.form.getFormItemsDisabled('head', 'zzhllyrq'); //表头本币汇率日期编辑性
             bodyarr.forEach((tablecode)=>{
                if(excludeBodyKey(tablecode)){
                    let allrows = props.cardTable.getAllRows(tablecode)
                    if (allrows){
                        allrows.forEach((row) => {

                            let currentrow_paytarget = props.cardTable.getValByKeyAndRowId(tablecode, row.rowid, 'paytarget')
                           
                            
                            if (currentrow_paytarget){
                                let currentrow_paytargetvalue = currentrow_paytarget.value
                                 //控制表体收款对象相关字段的可编辑性
                                let editablekeys = []
                                let uneditablekeys = []
                                if ("0" == currentrow_paytargetvalue){
                                    editablekeys = ['receiver','skyhzh']
                                    uneditablekeys = ['hbbm','hbbm_v','customer','customer_v','custaccount']
                                }else if("1" == currentrow_paytargetvalue){
                                    editablekeys = ['hbbm','hbbm_v','custaccount']
                                    uneditablekeys = ['receiver','skyhzh','customer','customer_v']
                                }else if("2" == currentrow_paytargetvalue){
                                    editablekeys = ['customer','customer_v','custaccount']
                                    uneditablekeys = ['receiver','skyhzh','hbbm','hbbm_v']
                                }
                                props.cardTable.setEditableByRowId(tablecode, row.rowid, editablekeys, true)
                                props.cardTable.setEditableByRowId(tablecode, row.rowid, uneditablekeys, false)
                            }
                            // 表头中本币种、汇率类型更改后，表体中本币汇率、汇率类型、汇率来源日期需同时控制其编辑性
                            let editkeys = []
                            let unedikeys = []
                            bbhlFlag ? unedikeys.push('bbhl') : editkeys.push('bbhl')
                            zzhllxFlag ? unedikeys.push('zzhllx') : editkeys.push('zzhllx')
                            zzhllyrqFlag ? unedikeys.push('zzhllyrq') : editkeys.push('zzhllyrq')
                            props.cardTable.setEditableByRowId(tablecode, row.rowid, editkeys, true)
                            props.cardTable.setEditableByRowId(tablecode, row.rowid, unedikeys, false)

                        })
                    }
                }
             })   
             setImportConfig(this)
            break;
        default:
            //表体字段处理
            //满足报销标准核心控制项字段影响因素
            if(key!=window.presetVar.showitemkey 
                 && ( (window.presetVar.reimsrc!=null && window.presetVar.reimsrc.length>0 && window.presetVar.reimsrc.includes(key))
                    ||  (window.presetVar.reimruleitemkeys!=null && window.presetVar.reimruleitemkeys.length>0 && window.presetVar.reimruleitemkeys.indexOf(key) != -1) )
            ) {
                //清空当前行报销标准的值，以重新获取
                let newvalue = changedrows[0].newvalue.value==null?'':changedrows[0].newvalue.value;
                let oldvalue = changedrows[0].oldvalue.value==null?'':changedrows[0].oldvalue.value;
                if(newvalue==oldvalue){
                    break;
                }
                let billdata = props.createBodyAfterEventData('20110ETEA_2641_IWEB', "head", bodyarr, moduleId, key, value);
                console.log('表头字段change后表头标题数据结构：', billdata);
                paramdata.checkrule='true';
                if(!value || value.value==undefined||value.value==null){
                    paramdata.value = changedrows[0].newvalue.value;
                }
                billdata.card.head.userjson = JSON.stringify(paramdata);
                billdata.templetid =props.meta.getMeta().pageid;

                // let send_headdata = {billdata,paramdata};
                // send_headdata.templateid = props.meta.getMeta().pageid;
                requestApi.valueChange({
                    data: billdata.card,
                    success: (data)=> {
                        beforeUpdatePage(props);
                        //设置表头数据
                        let filterdata = requestApi.filterDatas(data.head[presetVar.head.head1]);
                        // TOP 性能优化，变更页面数据更新方法 chengwbc MOD
                        // props.form.setAllFormValue({[presetVar.head.head1]: filterdata});
                        updataFormData(props, presetVar.head.head1, filterdata);
                        // BTM 性能优化，变更页面数据更新方法
                        window.presetVar.reloadHead = filterdata;
                        //设置表体数据
                        // props.cardTable.setTableData(presetVar.body.body1, data.data.body[presetVar.body.body1]);
                        let filterbodydatas = requestApi.filterDatas(data.bodys[moduleid]);
                        if(filterbodydatas&&filterbodydatas.rows){
                            let rows = []
                            for(let i=0;i<filterbodydatas.rows.length;i++){
                                if(filterbodydatas.rows[i].values&&filterbodydatas.rows[i].values.tablecode&&filterbodydatas.rows[i].values.tablecode.value==moduleid){
                                    rows[rows.length] = filterbodydatas.rows[i];
                                }
                            }
                            filterbodydatas.rows = rows;
                        }
                            // TOP 性能优化，变更页面数据更新方法 chengwbc MOD
                            // props.cardTable.setTableData(moduleid,filterbodydatas);
                        updatacardTableData(props, moduleid, filterbodydatas);
                            // BTM 性能优化，变更页面数据更新方法
                        // let billdatas = props.createExtCardData(window.presetVar.pageId, window.presetVar.head.head1,bodyarr);
                        // requestApi.handleLoadDataResDada(props.meta.getMeta(), {data:billdatas},props,moduleid);
                        props.cardTable.updateDataByRowId(moduleid, filterbodydatas);
                        // props.cardTable.setTableData(moduleid,filterbodydatas);
                        updatePage(props, presetVar.head.head1, [moduleid]);

                    }
                })
            }
            switch (key){
                case 'iscompanypay'://是否企业支付
                case 'pk_org'://表体财务组织
                case 'pk_pcorg': // 利润中心
                case 'djrq'://表体单据日期
                case 'bzbm'://表体币种
                case 'bbhl'://表体本币汇率
                case 'dwbm_v'://表体借款报销人单位版本
                case 'dwbm'://表体借款报销人单位
                case 'fydwbm_v'://表体费用承担单位版本
                case 'fydwbm'://表体费用承担单位
                case 'pk_payorg_v'://表体支付单位版本
                case 'pk_payorg'://表体支付单位
                case "assume_org"://分摊页签表体承担单位编辑后事件
                case "assume_dept"://分摊页签表体承担部门编辑后事件
                case "pk_iobsclass"://分摊页签表体收支项目编辑后事件
                case "assume_amount"://分摊页签表体承担金额编辑后事件
                case 'deptid_v':// 表体报销人部门版本
                case 'deptid':// 表体报销人部门
                case 'fydeptid_v':// 表体费用承担部门版本
                case 'fydeptid':// 表体费用承担部门
                case "jkbxr"://借款报销人
                case "receiver"://表体收款人
                case "szxmid"://表体收支项目
                case "skyhzh"://表体个人银行账户
                case "jobid"://表体项目
                case "freecust"://散户
                case "custaccount"://表体客商银行账户
                case "paytarget"://表体收款对象
                case "hbbm"://表体供应商
                case "customer"://表体客户
                case "customer_v":
                case "hbbm_v":
                case "vat_amount"://表体含税金额
                case 'tni_amount'://表体不含税金额
                case 'tax_amount'://表体税金
                case 'amount'://表体报销金额
                case 'ybje'://原币金额
                case 'tax_rate'://表体税率
                case 'reimrule'://报销标准
                case 'defitem24'://新增项目todo
                case 'pk_erminvoice'://费用发票
                case 'share_ratio'://费用报销明细分摊比例
                case "zzhllyrq"://组织汇率来源日期
                case "zzhllx"://组织汇率类型
                case "inputtax"://进项税额

                    //let billdata = props.createHeadAfterEventData('20110ETEA_2641_IWEB', "head",[moduleid], moduleId, key, value);
                    // let data = props.createGridAfterEventData('20521030', moduleid, moduleId, key, changedrows);
                    // let billdata = props.createBodyAfterEventData('20110ETEA_2641_IWEB', 'head', moduleid, moduleId, key, changedrows);
                    let newvalue = changedrows[0].newvalue.value==null?'':changedrows[0].newvalue.value;
                    let oldvalue = changedrows[0].oldvalue.value==null?'':changedrows[0].oldvalue.value;
                    if(newvalue==oldvalue){
                        break;
                    }

                    let billdata = props.createBodyAfterEventData('20110ETEA_2641_IWEB', "head", bodyarr, moduleId, key, value);
                    console.log('表头字段change后表头标题数据结构：', billdata);
                    if(value.value==undefined||value.value==null){
                        paramdata.value = changedrows[0].newvalue.value;
                    }
                    billdata.card.head.userjson = JSON.stringify(paramdata);
                    billdata.card  = JSON.parse(JSON.stringify(billdata.card))
                    billdata.templetid =props.meta.getMeta().pageid;
                    // let send_headdata = {billdata,paramdata};
                    // send_headdata.templateid = props.meta.getMeta().pageid;
                    requestApi.valueChange({
                        data: billdata.card,
                        success: (data)=> {
                            beforeUpdatePage(props);
                            //设置表头数据
                            let filterdata = requestApi.filterDatas(data.head[presetVar.head.head1]);
                            // TOP 性能优化，变更页面数据更新方法 chengwbc MOD
                            // props.form.setAllFormValue({[presetVar.head.head1]: filterdata});
                            updataFormData(props, presetVar.head.head1, filterdata);
                            // BTM 性能优化，变更页面数据更新方法
                            window.presetVar.reloadHead = filterdata;
                            //设置表体数据
                            // props.cardTable.setTableData(presetVar.body.body1, data.data.body[presetVar.body.body1]);
                            let filterbodydatas = requestApi.filterDatas(data.bodys[moduleid]);
                            if(filterbodydatas&&filterbodydatas.rows){
                                let rows = []
                                for(let i=0;i<filterbodydatas.rows.length;i++){
                                    if(filterbodydatas.rows[i].values&&filterbodydatas.rows[i].values.tablecode&&filterbodydatas.rows[i].values.tablecode.value==moduleid){
                                        rows[rows.length] = filterbodydatas.rows[i];
                                    } else if(moduleid === 'er_cshare_detail') { //分摊没有tablecode，不走过滤
                                        rows[rows.length] = filterbodydatas.rows[i];
                                    }
                                }
                                filterbodydatas.rows = rows;
                            }
                            // TOP 性能优化，变更页面数据更新方法 chengwbc MOD
                            // props.cardTable.setTableData(moduleid,filterbodydatas);
                            updatacardTableData(props, moduleid, filterbodydatas);
                            // BTM 性能优化，变更页面数据更新方法
                            // let billdatas = props.createExtCardData(window.presetVar.pageId, window.presetVar.head.head1,bodyarr);
                            // requestApi.handleLoadDataResDada(props.meta.getMeta(), {data:billdatas},props,moduleid);
                            
                            //fix: setTableDataWithResetInitValue会导致表体的index丢失
                            let currentIndex = props.cardTable.getCurrentIndex(moduleid);
                            props.cardTable.updateDataByRowId(moduleid, filterbodydatas);
                            props.cardTable.focusRowByIndex(moduleid, currentIndex)
                            // props.cardTable.setTableData(moduleid,filterbodydatas);
                            updatePage(props, presetVar.head.head1, [moduleid]);
                        }
                    })


                    //编辑后事件控制字段可编辑性需要放到valuechange之后
                    let currentrow_paytarget = props.cardTable.getValByKeyAndRowId(moduleId, changedrows[0].rowid, 'paytarget')
                    if (currentrow_paytarget){
                        let currentrow_paytargetvalue = currentrow_paytarget.value
                         //控制表体收款对象相关字段的可编辑性
                        let editablekeys = []
                        let uneditablekeys = []
                        if ("0" == currentrow_paytargetvalue){
                            editablekeys = ['receiver','skyhzh']
                            uneditablekeys = ['hbbm','hbbm_v','customer','customer_v','custaccount']
                        }else if("1" == currentrow_paytargetvalue){
                            editablekeys = ['hbbm','hbbm_v','custaccount']
                            uneditablekeys = ['receiver','skyhzh','customer','customer_v']
                        }else if("2" == currentrow_paytargetvalue){
                            editablekeys = ['customer','customer_v','custaccount']
                            uneditablekeys = ['receiver','skyhzh','hbbm','hbbm_v']
                        }
                        props.cardTable.setEditableByRowId(moduleId, changedrows[0].rowid, editablekeys, true)
                        props.cardTable.setEditableByRowId(moduleId, changedrows[0].rowid, uneditablekeys, false)
                    }
                    // 表体编辑后，本币汇率、本币汇率日期、本币汇率来源日期编辑性设置
                    // 新增汇率适配逻辑
                    let currentrow_bzbm = props.cardTable.getValByKeyAndRowId(moduleId, changedrows[0].rowid, 'bzbm')
                    let rate_category = props.cardTable.getValByKeyAndRowId(moduleId, changedrows[0].rowid, 'zzhllx.rate_category')
                    zzhllxLogic(currentrow_bzbm,rate_category,'body',props,moduleId,changedrows[0].rowid)
            }
            break;
    }
};

/**
 * 表头字段（收款对象、收款人、个人银行账号、供应商、客户、客商银行账户、散户）值修改时
 * 将表体默认值一并修改
 */
function resetBodyInitValue(metas, bodyarr, headrows, key){
    let changeKeys = ["paytarget","receiver","skyhzh","hbbm","custaccount","freecust","customer"];
    if(!changeKeys.includes(key)){
        return metas;
    }
    bodyarr.forEach((body) =>{
        metas[body].items.forEach((item)=>{
            if(item && item.attrcode && changeKeys.includes(item.attrcode)){
                if(headrows[item.attrcode] && headrows[item.attrcode].value){
                    item.initialvalue = {
                        value: headrows[item.attrcode].value,
                        display: headrows[item.attrcode].display
                    }
                }else{
                    item.initialvalue = {
                        value: "",
                        display: ""
                    }
                }
                
            }
        })
    })
    return metas;
}

export function setImportConfig(prop){
    let that = prop;
    let props = prop.props;
    let tabledata = [];
    let formdata = props.createExtCardData(props.meta.getMeta().pageid, "head", ['er_cshare_detail']);
    props.meta.getMeta().er_cshare_detail.items.forEach((item) =>{
        if(item.attrcode !="opr"){
            tabledata.push({"visible":item.visible,"key":item.attrcode,"label":item.label,"itemtype":item.itemtype,"initialvalue":item.initialvalue && item.initialvalue.value?item.initialvalue.value:""});
        }
    });
    formdata.userjson = JSON.stringify(tabledata);
    let config = getExcelImportConfig('/nccloud/erm/expenseaccount/ExpenseaccountCshareImportAction.do',formdata,(resultinfo)=>{
        if (resultinfo == 'beginUpload') {
        } else if (resultinfo.success) {
            let exceldata = resultinfo.data.bodys.er_cshare_detail;
            that.props.cardTable.setTableData('er_cshare_detail',  exceldata);

        }
    });

    that.props.button.setUploadConfig('er_cshare_detail_Import', config);
}


